
cc.Class({
    extends: cc.Component,

    properties: {
        m_ProMaxLen:{
            default:445,
            type:cc.Integer
        },
        m_ProImage:cc.Node,
        m_Speed:{
            default:200,
            type:cc.Integer
        },
        m_ProgressLabel:{
            default:null,
            type:cc.Label
        },
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.m_ProImage.width = 0;
        this.m_ProgressLabel.color = cc.color(255,255,0,255);
    },

    ctor:function() {
        this.m_progressIng = false;
    },
    // 规定进度条整体长度百分比 0-1
    setProgress:function(pro) {
        if(pro > 1 || pro < 0) {
            return;
        }
        var width = this.m_ProMaxLen * pro;
        if(width < this.m_SetWidth){
            return;
        }
        this.m_SetWidth = this.m_ProMaxLen * pro;
        this.m_progressIng = true;
        // this.m_ProImage.width = setWidth;
    },

    start () {

    },

    update (dt) {
        if(this.m_progressIng) {
            
            if(this.m_ProImage.width < this.m_SetWidth){
                var num = this.m_ProImage.width / this.m_ProMaxLen * 100;
                this.m_ProgressLabel.string = parseInt(num) + "%";
                this.m_ProImage.width += dt * this.m_Speed;
            }
            if(this.m_ProImage.width >= this.m_ProMaxLen){
                this.m_progressIng = false;
                if(this.finishCallBack != null){
                    this.finishCallBack();
                }
            }
        }
    },
});
